package com.kkb.kkbportal.controller;

import com.github.pagehelper.PageInfo;
import com.kkb.kkbcommon.api.CommonPage;
import com.kkb.kkbcommon.api.CommonResult;
import com.kkb.kkbportal.domain.BrowsingHistory;
import com.kkb.kkbportal.service.BrowsingHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName ProjectRegisterController
 * @Description 历史浏览
 * @Author hxf
 * @Date 2021/8/14
 **/
@RestController
@Api(tags = "历史浏览API", description = "历史浏览记录查询")
@RequestMapping("histroy")
public class BrowsingHistroyController {
    @Resource
    private BrowsingHistoryService service;

    @ApiOperation(value = "历史浏览记录查询", notes = "显示所有项目历史记录")
    @GetMapping("/history")
    public CommonResult<CommonPage<BrowsingHistory>> list(@Validated @PathVariable("userId") Long userId) {
        List<BrowsingHistory> list = service.list(userId);
        CommonPage<BrowsingHistory> page = CommonPage.restPage(list);
        return CommonResult.success(page);
    }

    @ApiOperation(value = "分页查询历史浏览记录", notes = "分页显示所有项目历史记录")
    @GetMapping("/historys")
    public CommonResult<CommonPage<BrowsingHistory>> list(@Validated @PathVariable("userId") Long userId,
                                                          @Validated @RequestParam(defaultValue = "1") int pageNum,
                                                          @Validated @RequestParam(defaultValue = "10") int pageSize) {
        PageInfo<BrowsingHistory> pageInfo = service.listByUserId(userId, pageNum, pageSize);
        CommonPage<BrowsingHistory> page = CommonPage.restPage(pageInfo.getList());
        return CommonResult.success(page);
    }
}

